// Selection management
// Copyright 2006 (C) Ralph Thomas

#ifndef MISSION_TOOLKIT_SELECTION_H
#define MISSION_TOOLKIT_SELECTION_H

#include <adobe/value.hpp>
#include <adobe/array.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/signals.hpp>
#include <set>
#include <map>
#include <algorithm>
#include <util/cow_vector.h>
#include <binder.hpp>
#include <iostream>

namespace toolkit {
	struct selection_t {
		typedef enum { kSelected, kUnselected, kPartial } selected_state_t;
		typedef boost::function<void (selected_state_t)> monitor_t;
		typedef boost::function<void (const adobe::value_t&)> monitor_all_t;
		typedef monitor_all_t monitor_value_t;
		typedef boost::signals::connection connection_t;
		typedef boost::signals::scoped_connection scoped_connection_t;
		typedef std::vector<unsigned int>	index_list_t;

		virtual ~selection_t() {}
		virtual adobe::value_t get_primary() = 0;
		virtual unsigned int get_index(const adobe::value_t& v) = 0;
		virtual void toggle(const adobe::value_t& v) = 0;
		virtual void unselect_all() = 0;
		virtual void select_all() = 0;
		virtual void set_state(unsigned int index, selected_state_t state) = 0;
		virtual void select_range(unsigned int start, unsigned int end) = 0;
		virtual selected_state_t is_selected(unsigned int index) = 0;
		virtual void set_primary(const adobe::value_t& v) = 0;
		virtual void set_primary(unsigned int index) = 0;
		virtual void monitor(const adobe::value_t& v, const monitor_t& monitor) = 0;
		virtual void unmonitor(const adobe::value_t& v) = 0;
		virtual connection_t monitor_next(const monitor_value_t& next) = 0;
		virtual connection_t monitor_prev(const monitor_value_t& previous) = 0;
		virtual connection_t monitor_all(const monitor_all_t& monitor) = 0;
		virtual connection_t monitor_primary(const monitor_value_t& monitor) = 0;
	};
	typedef boost::shared_ptr<selection_t> selection_ptr_t;
	adobe::value_t make_string_selection(const adobe::array_t& name_of_universe, adobe::sheet_t& sheet);
	adobe::value_t make_int_selection(const adobe::array_t& name_of_universe, adobe::sheet_t& sheet);
};

#endif
